//
//  CloningViewController.swift
//  GitTFGUI
//
//  Created by Samuel Richard Magny on 2015-08-30.
//  Copyright (c) 2015 Samuel Richard Magny. All rights reserved.
//

import Cocoa

class CloningViewController: NSViewController, TFSClientViewControllerProtocol {

    static let storyboardId:String = "CloningViewController"
    
    var tfsClient:ExtendedTFSClient?
    
    var cloningBlock:(() -> ())?

    @IBOutlet var serverUrlTextField: NSTextField!
    @IBOutlet var projectPathTextField: NSTextField!
    @IBOutlet var existingDirectoryCheckbox: NSButton!
    
    @IBOutlet var cloneButton: NSButton!
    @IBOutlet var cancelButton: NSButton!
    
    override func viewDidLoad() {
        super.viewDidLoad()
        
        if let tfsClient = self.tfsClient {
            serverUrlTextField.stringValue = tfsClient.projectDirectoryServerUrl
            projectPathTextField.stringValue = tfsClient.projectDirectoryServerPath
            
            
            
            
            
            let isDirectoryActive = tfsClient.isCurrentWorkingDirectoryValid()
            
            cancelButton.hidden = isDirectoryActive
            existingDirectoryCheckbox.hidden = isDirectoryActive
            serverUrlTextField.editable = !isDirectoryActive
            projectPathTextField.editable = !isDirectoryActive
            
            if isDirectoryActive
            {
                cloneButton.title = "Close"
            }
            else {
                cloneButton.title = "Clone"
            }
            
            
            
        }
    }
    
    
    @IBAction func yesButtonPressed(sender: NSButton) {
       
        if (!cancelButton.hidden) {
            //Make cloning things...
        }
        
        self.dismissController(sender);
    }
    
    @IBAction func noButtonPressed(sender: NSButton) {
        self.dismissController(sender);
    }
    
}
